package com.lxq.blog.com.lxq.blog.dao;

import com.lxq.blog.com.lxq.blog.entity.Blog;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

@Mapper
public interface BlogDao {
    @Insert("insert into blog(id,title,description,cover,username,date,reading,content,thumb)" +
            " values(#{id},#{title},#{description},#{cover},#{username},#{date}" +
            ",#{reading},#{content},#{thumb})")
    boolean saveBlog(Blog blog);

    @Select("select * from blog")
    ArrayList<Blog> findAll();

    @Select("select * from blog where id=#{id}")
    Blog findById(String id);

    @Delete("delete from blog where id=#{id}")
    boolean deleteById(String id);

    @Update("update blog set title=#{title},description=#{description},content=#{content} where id=#{id}")
    boolean updateById(Blog blog);

    @Update("update blog set reading=reading+1 where id=#{id}")
    boolean viewUp(String id);

//    @Select("update blog set thumb=thumb+1 where id=#{id};select thumb from blog where id=#{id}")
    @Update("update blog set thumb=thumb+1 where id=#{id}")
    boolean thumbUp(String id);

    @Select("select thumb from blog where id=#{id}")
    int queryThumbById(String id);
}
